"""

"""
login_url = 'http://localhost:8080/ecshop/user.php'
from Common.Base import Base


class ProductSearchZ(Base):
    """封装表现层:制作定位器的过程"""
    search_loc = ('id', 'keyword')  # 搜索框定位器
    username_loc = ('name', 'username')  # 输入用户名定位器
    password_loc = ('name', 'password')  # 输入密码框定位器
    remember_loc = ('name', 'remember')  # 记住密码定位器
    submit_loc = ('name', 'submit')  # 登录按钮定位器
    search_button_loc = ('name', 'imageField')  # 搜索按钮定位器
    product_loc = ('css selector', 'div[class="goodsItem"]')  # 商品定位器
    no_result_loc = ('css selector', 'div[class="f5"]')  # 没有商品时的提示定位器
    """封装操作层:针对表现层中元素的操作"""

    def input_username(self, username):
        """
        输入用户名
        :param username: 用户名
        :return:
        """
        self.send_keys(self.username_loc, username)

    def input_password(self, password):
        """
        输入密码
        :param password: 密码
        :return:
        """
        self.send_keys(self.password_loc, password)

    def click_login(self):
        """
        点击登录按钮
        :return:
        """
        self.click(self.submit_loc)

    def input_product_name_z(self, text):
        """
        给输入框传入输入内容
        :return:
        """
        self.send_keys(self.search_loc, text)

    def click_search_z(self):
        """
        点击搜索按钮
        :return:
        """
        self.click(self.search_button_loc)

    def is_have_search_goods_z(self):
        """
        判断是否有搜索后的商品
        :return:
        """
        result = self.find_element(self.product_loc)
        if result is not False:
            return True
        else:
            return False

    def get_num_goods(self):
        """
        获取搜索后商品的数量
        :return: 商品数量/False
        """
        result = self.find_elements(self.product_loc)
        if result is not False:
            return len(result)
        else:
            return False

    def is_have_text(self):
        """
        判断是否有提示"无法搜索到您要找的商品！"
        :return:
        """
        result = self.find_element(self.no_result_loc)
        if result is not False:
            return True
        else:
            return False
